﻿#region Using directives

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using NetROS.Tiers.Entities;
using NetROS.Tiers.Data;

#endregion

namespace NetROS.Tiers.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="VwObracunSpecifikacijaPoBankamaProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract class VwObracunSpecifikacijaPoBankamaProviderBaseCore : EntityViewProviderBase<VwObracunSpecifikacijaPoBankama>
	{
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions
		
		/*
		///<summary>
		/// Fill an VList&lt;VwObracunSpecifikacijaPoBankama&gt; From a DataSet
		///</summary>
		/// <param name="dataSet">the DataSet</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList&lt;VwObracunSpecifikacijaPoBankama&gt;"/></returns>
		protected static VList&lt;VwObracunSpecifikacijaPoBankama&gt; Fill(DataSet dataSet, VList<VwObracunSpecifikacijaPoBankama> rows, int start, int pagelen)
		{
			if (dataSet.Tables.Count == 1)
			{
				return Fill(dataSet.Tables[0], rows, start, pagelen);
			}
			else
			{
				return new VList<VwObracunSpecifikacijaPoBankama>();
			}	
		}
		
		
		///<summary>
		/// Fill an VList&lt;VwObracunSpecifikacijaPoBankama&gt; From a DataTable
		///</summary>
		/// <param name="dataTable">the DataTable that hold the data.</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList<VwObracunSpecifikacijaPoBankama>"/></returns>
		protected static VList&lt;VwObracunSpecifikacijaPoBankama&gt; Fill(DataTable dataTable, VList<VwObracunSpecifikacijaPoBankama> rows, int start, int pagelen)
		{
			int recordnum = 0;
			
			System.Collections.IEnumerator dataRows =  dataTable.Rows.GetEnumerator();
			
			while (dataRows.MoveNext() && (pagelen != 0))
			{
				if(recordnum >= start)
				{
					DataRow row = (DataRow)dataRows.Current;
				
					VwObracunSpecifikacijaPoBankama c = new VwObracunSpecifikacijaPoBankama();
					c.IDObracun = (Convert.IsDBNull(row["IDObracun"]))?(int)0:(System.Int32)row["IDObracun"];
					c.NazivBanke = (Convert.IsDBNull(row["NazivBanke"]))?string.Empty:(System.String)row["NazivBanke"];
					c.BrojRacunaBanke = (Convert.IsDBNull(row["BrojRacunaBanke"]))?string.Empty:(System.String)row["BrojRacunaBanke"];
					c.ModelZaIsplatuBanci = (Convert.IsDBNull(row["ModelZaIsplatuBanci"]))?string.Empty:(System.String)row["ModelZaIsplatuBanci"];
					c.PozivZaIsplatuBanci = (Convert.IsDBNull(row["PozivZaIsplatuBanci"]))?string.Empty:(System.String)row["PozivZaIsplatuBanci"];
					c.PrezimeIme = (Convert.IsDBNull(row["PrezimeIme"]))?string.Empty:(System.String)row["PrezimeIme"];
					c.BrojRacunaOsobe = (Convert.IsDBNull(row["BrojRacunaOsobe"]))?string.Empty:(System.String)row["BrojRacunaOsobe"];
					c.ZaIsplatu = (Convert.IsDBNull(row["ZaIsplatu"]))?0:(System.Decimal?)row["ZaIsplatu"];
					c.DatumIsplate = (Convert.IsDBNull(row["DatumIsplate"]))?DateTime.MinValue:(System.DateTime)row["DatumIsplate"];
					c.AcceptChanges();
					rows.Add(c);
					pagelen -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		*/	
						
		///<summary>
		/// Fill an <see cref="VList&lt;VwObracunSpecifikacijaPoBankama&gt;"/> From a DataReader.
		///</summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pageLength">number of row.</param>
		///<returns>a <see cref="VList&lt;VwObracunSpecifikacijaPoBankama&gt;"/></returns>
		protected VList<VwObracunSpecifikacijaPoBankama> Fill(IDataReader reader, VList<VwObracunSpecifikacijaPoBankama> rows, int start, int pageLength)
		{
			int recordnum = 0;
			while (reader.Read() && (pageLength != 0))
			{
				if(recordnum >= start)
				{
					VwObracunSpecifikacijaPoBankama entity = null;
					if (DataRepository.Provider.UseEntityFactory)
					{
						entity = EntityManager.CreateViewEntity<VwObracunSpecifikacijaPoBankama>("VwObracunSpecifikacijaPoBankama",  DataRepository.Provider.EntityCreationalFactoryType); 
					}
					else
					{
						entity = new VwObracunSpecifikacijaPoBankama();
					}
					entity.IDObracun = (System.Int32)reader["IDObracun"];
					//entity.IDObracun = (Convert.IsDBNull(reader["IDObracun"]))?(int)0:(System.Int32)reader["IDObracun"];
					entity.NazivBanke = reader.IsDBNull(reader.GetOrdinal("NazivBanke")) ? null : (System.String)reader["NazivBanke"];
					//entity.NazivBanke = (Convert.IsDBNull(reader["NazivBanke"]))?string.Empty:(System.String)reader["NazivBanke"];
					entity.BrojRacunaBanke = (System.String)reader["BrojRacunaBanke"];
					//entity.BrojRacunaBanke = (Convert.IsDBNull(reader["BrojRacunaBanke"]))?string.Empty:(System.String)reader["BrojRacunaBanke"];
					entity.ModelZaIsplatuBanci = (System.String)reader["ModelZaIsplatuBanci"];
					//entity.ModelZaIsplatuBanci = (Convert.IsDBNull(reader["ModelZaIsplatuBanci"]))?string.Empty:(System.String)reader["ModelZaIsplatuBanci"];
					entity.PozivZaIsplatuBanci = (System.String)reader["PozivZaIsplatuBanci"];
					//entity.PozivZaIsplatuBanci = (Convert.IsDBNull(reader["PozivZaIsplatuBanci"]))?string.Empty:(System.String)reader["PozivZaIsplatuBanci"];
					entity.PrezimeIme = (System.String)reader["PrezimeIme"];
					//entity.PrezimeIme = (Convert.IsDBNull(reader["PrezimeIme"]))?string.Empty:(System.String)reader["PrezimeIme"];
					entity.BrojRacunaOsobe = reader.IsDBNull(reader.GetOrdinal("BrojRacunaOsobe")) ? null : (System.String)reader["BrojRacunaOsobe"];
					//entity.BrojRacunaOsobe = (Convert.IsDBNull(reader["BrojRacunaOsobe"]))?string.Empty:(System.String)reader["BrojRacunaOsobe"];
					entity.ZaIsplatu = reader.IsDBNull(reader.GetOrdinal("ZaIsplatu")) ? null : (System.Decimal?)reader["ZaIsplatu"];
					//entity.ZaIsplatu = (Convert.IsDBNull(reader["ZaIsplatu"]))?0:(System.Decimal?)reader["ZaIsplatu"];
					entity.DatumIsplate = (System.DateTime)reader["DatumIsplate"];
					//entity.DatumIsplate = (Convert.IsDBNull(reader["DatumIsplate"]))?DateTime.MinValue:(System.DateTime)reader["DatumIsplate"];
					entity.AcceptChanges();
					rows.Add(entity);
					pageLength -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		
		
		/// <summary>
		/// Refreshes the <see cref="VwObracunSpecifikacijaPoBankama"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="VwObracunSpecifikacijaPoBankama"/> object to refresh.</param>
		protected void RefreshEntity(IDataReader reader, VwObracunSpecifikacijaPoBankama entity)
		{
			reader.Read();
			entity.IDObracun = (System.Int32)reader["IDObracun"];
			//entity.IDObracun = (Convert.IsDBNull(reader["IDObracun"]))?(int)0:(System.Int32)reader["IDObracun"];
			entity.NazivBanke = reader.IsDBNull(reader.GetOrdinal("NazivBanke")) ? null : (System.String)reader["NazivBanke"];
			//entity.NazivBanke = (Convert.IsDBNull(reader["NazivBanke"]))?string.Empty:(System.String)reader["NazivBanke"];
			entity.BrojRacunaBanke = (System.String)reader["BrojRacunaBanke"];
			//entity.BrojRacunaBanke = (Convert.IsDBNull(reader["BrojRacunaBanke"]))?string.Empty:(System.String)reader["BrojRacunaBanke"];
			entity.ModelZaIsplatuBanci = (System.String)reader["ModelZaIsplatuBanci"];
			//entity.ModelZaIsplatuBanci = (Convert.IsDBNull(reader["ModelZaIsplatuBanci"]))?string.Empty:(System.String)reader["ModelZaIsplatuBanci"];
			entity.PozivZaIsplatuBanci = (System.String)reader["PozivZaIsplatuBanci"];
			//entity.PozivZaIsplatuBanci = (Convert.IsDBNull(reader["PozivZaIsplatuBanci"]))?string.Empty:(System.String)reader["PozivZaIsplatuBanci"];
			entity.PrezimeIme = (System.String)reader["PrezimeIme"];
			//entity.PrezimeIme = (Convert.IsDBNull(reader["PrezimeIme"]))?string.Empty:(System.String)reader["PrezimeIme"];
			entity.BrojRacunaOsobe = reader.IsDBNull(reader.GetOrdinal("BrojRacunaOsobe")) ? null : (System.String)reader["BrojRacunaOsobe"];
			//entity.BrojRacunaOsobe = (Convert.IsDBNull(reader["BrojRacunaOsobe"]))?string.Empty:(System.String)reader["BrojRacunaOsobe"];
			entity.ZaIsplatu = reader.IsDBNull(reader.GetOrdinal("ZaIsplatu")) ? null : (System.Decimal?)reader["ZaIsplatu"];
			//entity.ZaIsplatu = (Convert.IsDBNull(reader["ZaIsplatu"]))?0:(System.Decimal?)reader["ZaIsplatu"];
			entity.DatumIsplate = (System.DateTime)reader["DatumIsplate"];
			//entity.DatumIsplate = (Convert.IsDBNull(reader["DatumIsplate"]))?DateTime.MinValue:(System.DateTime)reader["DatumIsplate"];
			reader.Close();
	
			entity.AcceptChanges();
		}
		
		/*
		/// <summary>
		/// Refreshes the <see cref="VwObracunSpecifikacijaPoBankama"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="VwObracunSpecifikacijaPoBankama"/> object.</param>
		protected static void RefreshEntity(DataSet dataSet, VwObracunSpecifikacijaPoBankama entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.IDObracun = (Convert.IsDBNull(dataRow["IDObracun"]))?(int)0:(System.Int32)dataRow["IDObracun"];
			entity.NazivBanke = (Convert.IsDBNull(dataRow["NazivBanke"]))?string.Empty:(System.String)dataRow["NazivBanke"];
			entity.BrojRacunaBanke = (Convert.IsDBNull(dataRow["BrojRacunaBanke"]))?string.Empty:(System.String)dataRow["BrojRacunaBanke"];
			entity.ModelZaIsplatuBanci = (Convert.IsDBNull(dataRow["ModelZaIsplatuBanci"]))?string.Empty:(System.String)dataRow["ModelZaIsplatuBanci"];
			entity.PozivZaIsplatuBanci = (Convert.IsDBNull(dataRow["PozivZaIsplatuBanci"]))?string.Empty:(System.String)dataRow["PozivZaIsplatuBanci"];
			entity.PrezimeIme = (Convert.IsDBNull(dataRow["PrezimeIme"]))?string.Empty:(System.String)dataRow["PrezimeIme"];
			entity.BrojRacunaOsobe = (Convert.IsDBNull(dataRow["BrojRacunaOsobe"]))?string.Empty:(System.String)dataRow["BrojRacunaOsobe"];
			entity.ZaIsplatu = (Convert.IsDBNull(dataRow["ZaIsplatu"]))?0:(System.Decimal?)dataRow["ZaIsplatu"];
			entity.DatumIsplate = (Convert.IsDBNull(dataRow["DatumIsplate"]))?DateTime.MinValue:(System.DateTime)dataRow["DatumIsplate"];
			entity.AcceptChanges();
		}
		*/
			
		#endregion Helper Functions
	}//end class

	#region VwObracunSpecifikacijaPoBankamaFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwObracunSpecifikacijaPoBankama"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwObracunSpecifikacijaPoBankamaFilterBuilder : SqlFilterBuilder<VwObracunSpecifikacijaPoBankamaColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwObracunSpecifikacijaPoBankamaFilterBuilder class.
		/// </summary>
		public VwObracunSpecifikacijaPoBankamaFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwObracunSpecifikacijaPoBankamaFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwObracunSpecifikacijaPoBankamaFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwObracunSpecifikacijaPoBankamaFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwObracunSpecifikacijaPoBankamaFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwObracunSpecifikacijaPoBankamaFilterBuilder

	#region VwObracunSpecifikacijaPoBankamaParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwObracunSpecifikacijaPoBankama"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwObracunSpecifikacijaPoBankamaParameterBuilder : ParameterizedSqlFilterBuilder<VwObracunSpecifikacijaPoBankamaColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwObracunSpecifikacijaPoBankamaParameterBuilder class.
		/// </summary>
		public VwObracunSpecifikacijaPoBankamaParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwObracunSpecifikacijaPoBankamaParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwObracunSpecifikacijaPoBankamaParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwObracunSpecifikacijaPoBankamaParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwObracunSpecifikacijaPoBankamaParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwObracunSpecifikacijaPoBankamaParameterBuilder
} // end namespace
